import {getOrderList} from '../../service/orders';

Page({
  data: {
    tabs: [
      {
        id: 0,
        title: '全部订单',
        isActive: true
      },
      {
        id: 1,
        title: '待付款',
        isActive: false
      },
      {
        id: 2,
        title: '待发货',
        isActive: false
      },
      {
        id: 3,
        title: '退款/退货',
        isActive: false
      },
    ]
  },
  onLoad(e) {
    let type = parseInt(e.type);
    this.pageInit(type);
  },
  pageInit: async function(type) {
    let orders = await getOrderList({type});
    this.handleTabClick(type - 1);
    
  },
  handleTabClick(e) {
    let id = e.detail === undefined ? e : e.detail.id;
    let {tabs} = this.data;
    tabs.forEach(v => {
      if(v.id == id) {
         return v.isActive = true;
      }
       return v.isActive = false;
    });
    this.setData({tabs})
  }
})